﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace modaid
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [DllImport("user32.dll", EntryPoint = "FindWindow")]
        private static extern IntPtr FindWindow(string lp1, string lp2);

        [DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool SetForegroundWindow(IntPtr hWnd);

        [DllImport("user32.dll")]
        public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

        private const int SW_SHOWNORMAL = 1; 

        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            HotKeyManager.RegisterHotKey(Keys.Z, KeyModifiers.Alt);
            HotKeyManager.HotKeyPressed += new EventHandler<HotKeyEventArgs>(HotKeyManager_HotKeyPressed);  
            Application.Run(new Form1());
               

        }

        static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e)
        {
            restoreModaid();
        }

        public static void restoreModaid()
        {
            IntPtr handle = FindWindow(null, "MODaid");
            if (!handle.Equals(IntPtr.Zero))
            {
                try
                {
                    ShowWindow(handle, SW_SHOWNORMAL);
                }
                catch
                {
                }
                if (SetForegroundWindow(handle))
                {
                    System.Drawing.Point cursorpoint = Cursor.Position;
                    cursorpoint.X -= 156;
                    cursorpoint.Y -= 128;
                    Form.ActiveForm.DesktopLocation = cursorpoint;
                }
            }
        }
    }
}
